package com.enbatis.mybatisplugs.component;
import com.alibaba.fastjson.JSONObject;
import com.enbatis.mybatisplugs.base.Account;
import com.enbatis.mybatisplugs.entity.SysMsg;
import com.enbatis.mybatisplugs.entity.dto.SysMsgDTO;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
//
//@Component
public class MsgSender {
    @Autowired
    private AmqpTemplate rabbitTemplate;
    public void send(String msg, List<Long> userIds, Account account) {
        SysMsg sysMsg = new SysMsg();
        sysMsg.setName(msg);
        sysMsg.setSender(account.getUsername());
        sysMsg.setSenderId(account.getId());
        sysMsg.setCtime(new Date());
        sysMsg.setDeleted(0);
        sysMsg.setCompanyId(account.getCompanyId());

        SysMsgDTO dto = new SysMsgDTO();
        dto.setSysMsg(sysMsg);
        dto.setUserIds(userIds);
        String jsonObject =JSONObject.toJSONString(dto);
        this.rabbitTemplate.convertAndSend("msg_send",jsonObject);
    }


}
